package com.engineering.elink.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.engineering.elink.co.StaffCo;
import com.engineering.elink.common.ResultType;
import com.engineering.elink.service.StaffService;
import com.engineering.elink.util.MapConvert;

@RestController
@RequestMapping("/api/staff")
@Api(value = "员工接口(企业精英)")
public class StaffController {
	@Autowired
	private StaffService staffService;
	
	/**
	 * 设置/取消设置员工/精英
	 * @param staffUserId
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/staff", method = RequestMethod.POST)
	@ApiOperation(value = "设置/取消设置员工/精英")
	public Map<String, Object> staff(
			@ApiParam(value = "员工ID", required = true) @RequestParam(value = "staffUserId", required = true) String staffUserId,HttpServletRequest request) {
		String userId = (String) ((Map<String, Object>) request.getAttribute("userInfo")).get("userId");
		if (staffService.staff(userId, staffUserId)) {
			return MapConvert.getMap(ResultType.SUCCESS);
		}
		return MapConvert.getMap(ResultType.REQUEST_PARAMS_ERROR);
	}
	
	/**
	 * 对内获取企业精英列表
	 * @param staffCo
	 * @return
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/getStaffList", method = RequestMethod.GET)
	@ApiOperation(value = "获取企业--对内精英列表")
	public Map<String, Object> getStaffList(
			@ModelAttribute @Valid StaffCo staffCo,HttpServletRequest request) {
		String userId = (String) ((Map<String, Object>) request.getAttribute("userInfo")).get("userId");
		if (userId == null) {
			return MapConvert.getMap(ResultType.TOKEN_ERROR);
		}
		staffCo.setUserId(userId);
		return MapConvert.getMap(ResultType.SUCCESS, staffService.getStaffList(staffCo));
	}
	
	/**
	 * 对外--获取企业精英列表
	 * @param staffCo
	 * @return
	 */
	@RequestMapping(value = "/getOutStaffList", method = RequestMethod.GET)
	@ApiOperation(value = "获取企业对外---精英列表")
	public Map<String, Object> getOutStaffList(@ModelAttribute @Valid StaffCo staffCo,@ApiParam(value = "企业ID", required = true)
	@RequestParam(value="userId",required=true)String userId) {
		staffCo.setUserId(userId);
		return MapConvert.getMap(ResultType.SUCCESS, staffService.getStaffList(staffCo));
	}	
}
